package util;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;

public class Ferramentas {
	
	public static byte[] imageIconToByteArray(ImageIcon icon) {
		BufferedImage bi=new BufferedImage(icon.getImage().getWidth(null),
				icon.getImage().getHeight(null), BufferedImage.TYPE_INT_RGB);
		Graphics g = bi.createGraphics();

		g.drawImage(icon.getImage(), 0, 0, null);
		g.dispose();

		ByteArrayOutputStream stream = new ByteArrayOutputStream();
		try {
			ImageIO.write(bi, "jpeg", stream);
		} catch (IOException ex1) { }

		return stream.toByteArray();
	}
}
